<?php
include("../contents.php");
include("../security.php");
include("../settings.php");
include("../database.php");
include("../navigation.php");

if (!empty($_POST)) {
	if(!empty($_GET["dir"]) || (isset($_GET["dir"]) && $_GET["dir"]==0)) {
    	if ($_GET["dir"]==0) {
    		$row_act->id=0;
    		$row_act->name="/";
    	} else {
    		$act_dir=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."navigation WHERE id='". $_GET["dir"] ."'");
    		if (mysql_num_rows($act_dir)==1) {
    			$row_act=mysql_fetch_object($act_dir);
    			if (!Contents::presence_rights($row_act->presence)) {
    				die("Sie haben keinen Zugriff auf dieses Verzeichnis");
    			}
    			$GLOBALS["linkzusatz"]="&dir=". $row_act->id;
    		} else {
    			die("Da ist irgendwas schief gelaufen.");
    		}
    	}
    	if (!empty($_POST["url"]) && !empty($_POST["type"])) {
    		if (mysql_query("UPDATE ". $GLOBALS["db_pref"] ."navigation SET linktype='". $_POST["type"] ."', link='". $_POST["url"] ."', linktarget='". $_POST["target"] ."' WHERE id='". $row_act->id ."'")) {
    			header("Location:admin_navigation_overview.php?dir=". $row_act->id);
    		}
    	}
	}
}
echo "<"."?xml version=\"1.0\"?".">";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>Administration</title>
    <link media="screen" rel="stylesheet" href="css/style.css" type="text/css" />
    <script src="js/scripts.js" type="text/javascript"></script>
    <script language="JavaScript" type="text/javascript">
    <!--
    function submitForm(type, url) {
    	document.forms[0].elements["url"].value=url;
    	document.forms[0].elements["type"].value=type;
    	document.forms[0].submit();
    }
    // -->
    </script>
    </head>

    <body id="editgrey">
    <?php
    $GLOBALS["linkzusatz"]="";
    if(!empty($_GET["dir"]) || (isset($_GET["dir"]) && $_GET["dir"]==0)) {
    	if ($_GET["dir"]==0 && (isset($_GET["pres"]) && Contents::presence_rights($_GET["pres"]))) {
    		$row_act->id=0;
    		$row_act->presence=$_GET["pres"];
    		$row_act->name="/";
    	} else {
    		$act_dir=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."navigation WHERE id='". $_GET["dir"] ."'");
    		if (mysql_num_rows($act_dir)==1) {
    			$row_act=mysql_fetch_object($act_dir);
    			if (!Contents::presence_rights($row_act->presence)) {
    				die("Sie haben keinen Zugriff auf dieses Verzeichnis");
    			}
    			$GLOBALS["linkzusatz"].="&dir=". $row_act->id;
    		} else {
    			die("Da ist irgendwas schief gelaufen.");
    		}
    	}
    }
    ?>
   	<div id="overview">
   	  <h1>Navigationslink</h1>
   	  <img src="images/dir_symbol.gif" width="64" height="64" alt="" style="padding-right:20px;float:left;" />
   	  <p>Belegen Sie einen Navigationspunkt mit einem Link.</p>
   	  <br style="clear:both;" />
    </div>
    <div id="edit">
    <form id="linkform" action="<?php echo $_SERVER["PHP_SELF"]; ?>?<?php echo $GLOBALS["linkzusatz"]; ?>" method="post">
    <input type="hidden" name="url" value=""/>
    <input type="hidden" name="type" value=""/>
    <table style="width:100%;padding:0px; margin:0px;border-top:0px;border-left:1px solid #aaaaaa;border-right:1px solid #aaaaaa;border-bottom:1px solid #aaaaaa; background-color:#ffffff" cellspacing="0" cellpadding="0">
      <tr>
        <th style="border:1px solid #666666;">W&auml;hlen Sie einen Zielframe</th>
      </tr>
      <tr>
        <td style="padding:10px;" class="tdnormal">
    		<select size="1" name="target">
    			<option value="">Kein spezieller Frame</option>
    			<option value="_blank">Neues Fenster</option>
    			<option value="_self">Selber Frame</option>
    			<option value="_parent">&uuml;bergeordneter Frame</option>
    		</select>
        </td>
      </tr>
    </table>
    <br />
    <table style="width:100%;padding:0px; margin:0px;border-top:0px;border-left:1px solid #aaaaaa;border-right:1px solid #aaaaaa;border-bottom:1px solid #aaaaaa; background-color:#ffffff" cellspacing="0" cellpadding="0">
      <tr>
        <th style="border:1px solid #666666;">Externer Link</th>
      </tr>
      <tr>
        <td style="padding:10px;" class="tdnormal">
        	<input type="text" value="http://" name="extlink" size="40" />
        	<input type="button" value="Einf&uuml;gen" onclick="submitForm('2', document.forms[0].elements['extlink'].value);"/>
        </td>
      </tr>
    </table>
	<br />
    <table style="width:100%;padding:0px; margin:0px;border-top:0px;border-left:1px solid #aaaaaa;border-right:1px solid #aaaaaa;border-bottom:1px solid #aaaaaa; background-color:#ffffff" cellspacing="0" cellpadding="0">
      <tr>
        <th style="border:1px solid #666666;">W&auml;hlen Sie eine Seite</th>
      </tr>
      <tr>
        <td style="padding:10px;" class="tdnormal">
   			<?php
   				list_contents($row_act->presence);
   				echo "<br />";
		   	?>
        </td>
      </tr>
    </table>
	<br />
    <table style="width:100%;padding:0px; margin:0px;border-top:0px;border-left:1px solid #aaaaaa;border-right:1px solid #aaaaaa;border-bottom:1px solid #aaaaaa; background-color:#ffffff" cellspacing="0" cellpadding="0">
      <tr>
        <th style="border:1px solid #666666;">W&auml;hlen Sie einen Navigationspunkt</th>
      </tr>
      <tr>
        <td style="padding:10px;" class="tdnormal">
   			<?php
   				list_navigations($row_act->presence);
   				echo "<br />";
		   	?>
        </td>
      </tr>
    </table>
   	</form>
   	</div>
  </body>
</html>